package com.lxlg.lxlg_order.app.controller;

import com.alipay.api.AlipayApiException;
import com.lxlg.core.utils.Result;
import com.lxlg.lxlg_order.client.GoodsRefundClient;
import com.lxlg.lxlg_order.client.param.GoodsRefundForm;
import com.lxlg.lxlg_order.client.param.RefundMoneyForm;
import com.lxlg.lxlg_order.client.result.GoodsRefundInfo;
import com.lxlg.lxlg_order.service.service.GoodsRefundService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kevin
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/infra/goods-refund")
public class GoodsRefundController implements GoodsRefundClient {

    @Resource
    private GoodsRefundService goodsRefundService;

    @Override
    @PostMapping("requestReturn")
    @ApiOperation("发起退款")
    public Result<GoodsRefundInfo> requestReturn(@Valid @RequestBody GoodsRefundForm goodsRefundForm){
        return goodsRefundService.doRequserReturn(goodsRefundForm);
    }
    @Override
    @PostMapping("refundmoney")
    @ApiOperation("退款")
    public Result<?> refundmoney(@Valid @RequestBody RefundMoneyForm refundMoneyForm)  {
        try {
            return goodsRefundService.doRefund(refundMoneyForm);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        return  null;
    }

}

